﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";
}
<ul class="breadcrumb" style="margin-bottom: 7px;">
    <li><a href="#">首页</a> <span class="divider">/</span></li>
    <li><a href="#">系统管理</a> <span class="divider">/</span></li>
    <li class="active">栏目管理</li>
</ul>
<div style="text-align: right; padding-bottom: 5px">
    <button id="addBtn" class="button button-small button-primary">添加栏目</button>
</div>
<div id="t1"></div>
<script type="text/javascript">
    var store = null;
    BUI.use(['bui/extensions/treegrid', 'bui/data'], function (TreeGrid, Data) {
        var Grid = BUI.Grid;
        store = new Data.TreeStore({
            autoLoad: true,
            url: '/Admin/NavBar/AjaxGetList'
        });
        var tree = new TreeGrid({
            render: '#t1',
            autoRender: true,
            showLine: true,
            store: store,
            forceFit: true,
            plugins: [Grid.Plugins.AutoFit],
            columns: [
              { title: '栏目名称', sortable: false, dataIndex: 'text' },
              { title: '类型', sortable: false, dataIndex: 'NavType' },
              { title: '链接地址', sortable: false, dataIndex: 'NavUrl' },
              { title: '打开方式', sortable: false, dataIndex: 'OpenType' },
              { title: '显示', sortable: false, dataIndex: 'Status' },
              { title: '排序', sortable: false, dataIndex: 'Sort' },
              {
                  title: '操作', sortable: false, dataIndex: 'id', renderer: function (value, obj) {
                      return '<span class="grid-command" onclick="Edit(\'' + value + '\')">编辑</span><span class="grid-command" onclick="Delete(\'' + value + '\')" >删除</span>';
                  }
              }
            ]
        });
    });
    var Overlay = BUI.Overlay
    var dialog = null;
    $('#addBtn').click(function () {
        dialog = new Overlay.Dialog({
            title: '栏目管理->添加栏目',
            width: 580,
            closeAction: 'destroy',
            height: 360,
            buttons: [],
            bodyStyle: { 'padding': '0px' },
            bodyContent: '<iframe frameborder="0" style="width:570px;height:298px" src="/Admin/NavBar/AddNavBar"></iframe>'
        });
        dialog.show();
    })
    function Edit(id) {
        dialog = new Overlay.Dialog({
            title: '栏目管理->编辑栏目',
            width: 580,
            closeAction: 'destroy',
            height: 360,
            buttons: [],
            bodyStyle: { 'padding': '0px' },
            bodyContent: '<iframe frameborder="0" style="width:570px;height:298px" src="/Admin/NavBar/EditNavBar/' + id + '"></iframe>'
        });
        dialog.show();
    }
    function Delete(id) {
        if (confirm('确认删除？')) {
            $.ajax({
                type: 'post',
                dataType: 'json',
                url: '/Admin/NavBar/DelNavBar',
                data: { id: id },
                success: function (res) {
                    if (res.result == true) {
                        store.load();
                    } else {
                        alert(res.msg);
                    }
                }
            })
        }
    }
    function SubmitSuccess() {
        CloseWin();
        store.load();
    }
    function CloseWin() {
        dialog.close();
    }
</script>
